<?php
// 在不进行特殊设置的情况下，phpExcel将读取的单元格信息保存在内存中，可以通过
// PHPExcel_Settings::setCacheStorageMethod()
// 来设置不同的缓存方式，以达到降低内存消耗的目的

// 1. 将单元格数据序列化后保存在内存中
$cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_in_memory_serialized; 

// 2. 将单元格序列化后再进行Gzip压缩，然后保存在内存中
$cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_in_memory_gzip; 

// 3. 缓存在临时的磁盘文件中，速度可能会慢一些
$cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_discISAM;

// 4. 保存在php://temp
$cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_phpTemp;
$cacheSettings = array('memoryCacheSize'=>'16MB');
PHPExcel_Settings::setCacheStorageMethod($cacheMethod, $cacheSettings);

// 5. 数据缓存在 memcache
$cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_memcache;  
$cacheSettings = array( 
    'memcacheServer'  => 'localhost',  
    'memcachePort'    => 11211,  
    'cacheTime'       => 600  
);  
PHPExcel_Settings::setCacheStorageMethod($cacheMethod, $cacheSettings);

// 上面的设置需在 new PHPExcel() 前面
$cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_phpTemp;
$cacheSettings = array('memoryCacheSize'=>'16MB');
PHPExcel_Settings::setCacheStorageMethod($cacheMethod, $cacheSettings);
$objPHPExcel = new PHPExcel();